package com.kymatrix.kycarbon.xsmd.common.business.oss.controller;

import com.kymatrix.kycarbon.xsmd.common.business.common.ResultResp;
import com.kymatrix.kycarbon.xsmd.common.business.oss.model.entity.OssFile;
import com.kymatrix.kycarbon.xsmd.common.business.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "Minio文件上传")
@RestController
@Slf4j
public class OssController {
    @Resource
    private OssService ossService;


    /**
     * 文件上传
     */
    @ApiOperation(value = "文件上传", notes = "文件上传")
    @PostMapping("/minio/Upload")
    public ResultResp<OssFile> configUpload(@RequestParam("file") MultipartFile multipartFile) {
        try {
            OssFile ossFile = ossService.configUpload(multipartFile);
            return ResultResp.ok(ossFile);
        } catch (Exception ex) {
            log.error("OssController" + ex.getMessage(), ex);
            return ResultResp.error("上传失败");
        }
    }
}
